//
//  SSSUserManager.m
//  SSSMerchant
//
//  Created by 谢曦 on 2017/4/2.
//  Copyright © 2017年 xnxin. All rights reserved.
//

#import "SSSUserManager.h"
#define kUserInfoFile [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"SSSUserManager.data"]

static SSSUserModel *_user;

@implementation SSSUserManager

+ (instancetype)userManager
{
    static SSSUserManager *user = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        user = [[SSSUserManager alloc] init];
       
    });
    return user;
}
+ (void)userInfoWithDict:(NSDictionary*)dict{
    SSSUserModel *userModel = [SSSUserModel mj_objectWithKeyValues:dict];
  BOOL result=   [NSKeyedArchiver archiveRootObject:userModel toFile:kUserInfoFile];
    while (result==NO) {
        NSLog(@"归档失败");
        result= [NSKeyedArchiver archiveRootObject:userModel toFile:kUserInfoFile];
    }
    _user=userModel;
}
+ (void)userInfoWithUserModel:(SSSUserModel*)userModel{
   
    BOOL result=   [NSKeyedArchiver archiveRootObject:userModel toFile:kUserInfoFile];
    while (result==NO) {
        NSLog(@"归档失败");
        result= [NSKeyedArchiver archiveRootObject:userModel toFile:kUserInfoFile];
    }
    _user=userModel;
}

+(SSSUserModel *)getUserModel
{
      if (!_user) {
        SSSUserModel  *user=  [NSKeyedUnarchiver unarchiveObjectWithFile:kUserInfoFile];
        _user=user;

    }
         return _user;
}
@end
